package PracticeFinal;

import java.util.ArrayList;
import java.io.*;
class testArraylist1{
    public static void main(String[] args) {
        ArrayList<Salary> al=new ArrayList<Salary>();
        al.add(new Salary("202301","101","张三",2000,500));
        al.add(new Salary("202301","102","李四",2000,1000));
        al.add(new Salary("202302","101","张三",2000,300));
        try {
            ObjectOutputStream oos = new  ObjectOutputStream(new FileOutputStream("d://Salary.txt"));
            oos.writeObject(al);
            oos.close();
            ObjectInputStream ois = new  ObjectInputStream(new FileInputStream("d://Salary.txt"));
            ArrayList<Salary> a=(ArrayList<Salary>)(ois.readObject());
            for(Salary x:a)
                System.out.println(x);
            ois.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

class Salary implements Serializable{
    private String yearMonth;
    private String employerId;
    private String employerName;
    private int wage; //工资
    private int allowance;  //津贴

    public Salary(String yearMonth, String employerId, String employerName, int wage, int allowance) {
        super();
        this.yearMonth = yearMonth;
        this.employerId = employerId;
        this.employerName = employerName;
        this.wage = wage;
        this.allowance = allowance;
    }

    @Override
    public String toString() {
        return "Salary [yearMonth=" + yearMonth + ", employerId=" + employerId + ", employerName=" + employerName
                + ", wage=" + wage + ", allowance=" + allowance + "]";
    }

    public String getYearMonth() {
        return yearMonth;
    }

    public void setYearMonth(String yearMonth) {
        this.yearMonth = yearMonth;
    }

    public String getEmployerId() {
        return employerId;
    }

    public void setEmployerId(String employerId) {
        this.employerId = employerId;
    }

    public String getEmployerName() {
        return employerName;
    }

    public void setEmployerName(String employerName) {
        this.employerName = employerName;
    }

    public int getWage() {
        return wage;
    }

    public void setWage(int wage) {
        this.wage = wage;
    }

    public int getAllowance() {
        return allowance;
    }

    public void setAllowance(int allowance) {
        this.allowance = allowance;
    }

}